package com.saber;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.saber.util.RabbitmqUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * Created by PC on 2017/10/18.
 */
public class RoutingSendDirect {

    public static final String EXCHANGE_NAME = "direct_logs";
    // 路由关键字
    public static final String[] routingKeys = new String[]{"info" ,"warning", "error"};

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = RabbitmqUtil.buildConnection();
        Channel channel = connection.createChannel();

        //声明交换机
        channel.exchangeDeclare(EXCHANGE_NAME,"direct");
        //发送信息
        for (String routingKey : routingKeys) {
            String message = "RoutingSendDirect Send the message level:"+routingKey;
            channel.basicPublish(EXCHANGE_NAME,routingKey,null,message.getBytes());
            System.out.println("RoutingSendDirect Send "+routingKey+":" + message);
        }

        channel.close();
        connection.close();
    }
}
